<?php
/**
 * Description of ConnectionDB
 *
 * @author rocco, 30/10/2010
 */
require_once '../classes/LoadProperties.php';
class ConnectionDB
{
    private static $instance;
    private $connection;

    public function  __destruct()
    {
        $this->connection->close();
    }
    public static function getInstance()
    {
        if(self::$instance == null)
        {
            $c = __CLASS__;
            self::$instance = new $c;
        }
        return self::$instance;
    }

    public function connectToDB()
    {
        if($this->connection == null)
        {
            $loadProperties= new LoadProperties();
            $loadProperties->initDB();
            $user = $loadProperties->getUser();
            $database = $loadProperties->getDatabase() ;
            $password = $loadProperties->getPassword();
            $host = $loadProperties->getHost();

            $this->connection = new mysqli($host, $user, $password, $database);

            if (mysqli_connect_errno())
            {
                printf("Connect failed: %s\n", mysqli_connect_error());
                return null;
            }

        }
        return $this->connection;
    }
}
?>
